#include "dd_box_2d.h"

#include "util/mmgr.h"		// Needs to come in early

using namespace dd;

Box2D::Box2D() :
	m_IsFilled(false)
{
}

Box2D::~Box2D()
{

}

void Box2D::Render(DBG_BUFFER_2D* _pBuffer)
{
	math::Vec2	DX(m_To.x- m_From.x, 0);
	math::Vec2	DY(0, m_To.y- m_From.y);
	if (m_IsFilled)
	{
		FlushBuffer(_pBuffer);
		// have a way to set solid-color?
		COLOR Color = ColorRGBA( 255, 58, 58, 128);
		math::Vec2	From = m_From;
		math::Vec2	To = m_To;
		if (DX.x < 0) 
		{
			From.x = To.x;
			DX.x =-DX.x;
		}
		if (DY.y < 0)
		{
			From.y = To.y;
			DY.y =-DY.y;
		}

		AddVertex(_pBuffer, From, Color);
		AddVertex(_pBuffer, From+DX, Color);
		AddVertex(_pBuffer, From+DX+DY, Color);

		AddVertex(_pBuffer, From, Color);
		AddVertex(_pBuffer, From+DX+DY, Color);
		AddVertex(_pBuffer, From+DY, Color);
		FlushBufferTri(_pBuffer);
	}
	DX = math::Vec2(m_To.x- m_From.x, 0);
	DY = math::Vec2(0, m_To.y- m_From.y);
	AddLine(_pBuffer, m_From, m_From+DX, m_Color); 
	AddLine(_pBuffer, m_From, m_From+DY, m_Color); 
	AddLine(_pBuffer, m_To, m_To-DX, m_Color); 
	AddLine(_pBuffer, m_To, m_To-DY, m_Color); 
}

void Box2D::Setup(const math::Vec2& _From, const math::Vec2& _To, COLOR _Color, bool IsFilled)
{
	m_Color = _Color;
	m_From	= _From;
	m_To	= _To;
	m_IsFilled = IsFilled;
}
